package com.sphd.beautysalon.model;


import com.android.volley.VolleyError;
import com.sphd.beautysalon.info.RestaurantInfo;
import com.sphd.beautysalon.interfaces.VolleyJsonObjectCallBack;
import com.sphd.beautysalon.presenter.SupperMeangerPresenter;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
* Created by Hu on 2016/10/31
*/

public class SupperMeangerModelImpl implements SupperMeangerModel, VolleyJsonObjectCallBack {
    SupperMeangerPresenter supperMeangerPresenter;
    @Override
    public void sendUrl(String url, SupperMeangerPresenter supperMeangerPresenter) {
        volleyUtil.setJsonObjectRequest(url,this);
        this.supperMeangerPresenter=supperMeangerPresenter;
    }

    @Override
    public void onResponse(JSONObject response) {
        try {
            List<RestaurantInfo> restaurantInfos= JsonUtil.getListFromString(response.getString("list"),RestaurantInfo.class);
            double all=response.getDouble("all");
            double month =response.getDouble("month");
            double today=response.getDouble("today");
            supperMeangerPresenter.sendRes(all,month,today,restaurantInfos);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onErrorResponse(VolleyError error) {
        supperMeangerPresenter.sendError(error);
    }
}